﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    public class RecordIProvider : IProvider<Record>
    {    private SMEntities db=new SMEntities();
        public int Delete(int Id)
        {
               Record entity=  db.Record .Find(Id);
            if(entity != null)
            {
                db.Record .Remove(entity);
               int  A=   db.SaveChanges();
                return A;
            }
            return 0;
        }

        public List<Record> GetAll()
        {
            return  db.Record.ToList(); 
        }

        public int Insert(Record t)
        {
               db.Record.Add(t);
            int A= db.SaveChanges();
            return A;
        }

        public int Update(Record t)
        {
            Record entity = db.Record.FirstOrDefault(e => e.Id == t.Id);
            if(entity != null)
            {
                 // 修改实体属性值
            entity.CargoName = t.CargoName;
            entity.Tag = t.Tag;
            entity.Number = t.Number;
                
            return          db.SaveChanges();
            }
            return 0;
        }
            public Record GetById(int Id)
        {
            Record entity=  db.Record.Find(Id);
            return entity;
        }
    }
}
